package com.cykj.page01;

/**
 * @BelongsProject: HandTomcat
 * @BelongsPackage: com.cykj
 * @Author: WWJ
 * @CreateTime: 2025-06-18 01:06
 * @Description: 线程的实现方式之一：继承Thread
 * @Version: 1.0
 */
public class MyThread extends Thread{
    //执行
    @Override
    //ctrl+o
    //Thread.currentThread()：表示获取当前正在执行的线程对象
    //.getName()：是 Thread 类的实例方法，用来获取线程的名字
    public void run() {
        for (int i = 0; i < 20; i++) {
            try {
                //阻塞 抛异常
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            //currentThread().getName()
            System.out.println(currentThread().getName() + " " + i);
        }

        //GGG
        System.out.println("死亡");
    }

    public static void main(String[] args) {
        //创建线程
        MyThread t1 = new MyThread();
        MyThread t2 = new MyThread();
        //就绪
        t1.start();
        t2.start();
    }
}


